		//页面加载
		var orderMoney = 0,
			resPrice = 0,
			moneyDetail="";
		//清除优惠券数据 2017.7.17 GJC
		sessionStorage.removeItem("couponData");
		//初始化 获得地址页 地址信息
		//获取用户信息对象
		var userInfo = localStorage.getItem("userInfo");
		var userInfoObj = JSON.parse(userInfo);
		//获取用户地址本地存储信息
		var userAddStr = sessionStorage.getItem("userAddMes");
		var userAddObj = {},
			QuHuoAddress = "",
			ShouhuoAddress = "";
		if(userAddStr) {
			userAddObj = JSON.parse(userAddStr);
			QuHuoAddress = userAddObj.QuHuoAddress;
			ShouhuoAddress = userAddObj.ShouhuoAddress;
			$("#user_tel").val(userAddObj.Shouhuo_Tel);
		}
		//获取物品类型信息
		$.ajax({
		    type: "get",
		    url: currentUrl + "/interfaceDOC/firstProject/User.ashx?action=Get_WuPinHelper",
		    data: {
		        "Types": "0",
		    },
		    dataType: "json",
		    success: function (data) {
		        if (data.msgcode == "1") {
		            console.log(data);
		        }
		    }
		})
		//1：就近购买 isNearBuy
		var Near=sessionStorage.getItem("nearBuy");
		function nearBuyChange(){
			if(Near == "0") {
				$("#detail_address").empty();
				var $QuHuoAddress = "<p>" + QuHuoAddress + "</p>";
				var $ShouhuoAddress = "<p>" + ShouhuoAddress + "</p>";
				if(QuHuoAddress != ""&&ShouhuoAddress != "") {
					$("#detail_address").append($QuHuoAddress);
					$("#detail_address").append($ShouhuoAddress);
				}else if(QuHuoAddress == ""&&ShouhuoAddress != ""){
					$("#detail_address").append("<p style='color:#666'>请填写购买地址</p>")
					$("#detail_address").append($ShouhuoAddress);
					QuHuoAddress="";
				};
				
			} else {
				$("#near_buy").attr("checked","checked");
				if(ShouhuoAddress!=""){
					$("#detail_address").empty();
					var $QuHuoAddress = "<p style='color:red'>附近两公里有你购买的商品</p>";
					var $ShouhuoAddress = "<p>" + ShouhuoAddress + "</p>";
					$("#detail_address").append($QuHuoAddress);
					$("#detail_address").append($ShouhuoAddress);
				}else if(ShouhuoAddress==""){
					var $QuHuoAddress = "<p style='color:red'>附近两公里有你购买的商品</p>";
					var $ShouhuoAddress = "<p style='color:#666'>请填写收货地址</p>";
					$("#detail_address").append($QuHuoAddress);
					$("#detail_address").append($ShouhuoAddress);
				}
			}
		}
		nearBuyChange();
		$("#near_buy").click(function() {
			var isNearBuy = $(this).is(':checked');
			if(isNearBuy == false) {
				Near = "0";
				sessionStorage.setItem('nearBuy', Near);		
				ajaxOrderMoney();
			} else {
				Near = "1";
				sessionStorage.setItem('nearBuy', Near);
				ajaxNearOrderMoney();
			}
			nearBuyChange();
		});
		
		
		//知道商品价格对应样式
		var zhiPrice = sessionStorage.getItem("zhiPrice");
		// var resPrice = "0";
		function knowPriceStyle() {
			var str = "";
			var noknowPrice = $("#know_price").is(':checked');
			if(noknowPrice == true) {
				str = "<span style='color:red;'>凭购物小票线下支付</span>";
				$("#know_price").parent().prev(".item_price").html(str);
				resPrice = "0";
				(Near=="0" ? ajaxOrderMoney() : ajaxNearOrderMoney());
				zhiPrice = "0";
				sessionStorage.setItem('zhiPrice', zhiPrice);
			} else {
				str = "<input id='res_price' type='tel' placeholder='请输入商品金额'/>";
				$("#know_price").parent().prev(".item_price").html(str);
				zhiPrice = "1";
				sessionStorage.setItem('zhiPrice', zhiPrice);
			}
		}
		knowPriceStyle(); //读取知道价格信息 刷新样式;
		//知道价格点击
		$("#know_price").click(knowPriceStyle);
		//商品金额
		$('.item_price').on("keyup",'#res_price',function(){
			resPrice = $('#res_price').val();
				if(resPrice == "") {
					resPrice = "0";
				}
				(Near=="0" ? ajaxOrderMoney() : ajaxNearOrderMoney());
				console.log(resPrice)
		})
		//获取订单金额
		function ajaxOrderMoney() {
			$.ajax({
				type: "post",
				url: currentUrl+"/interfaceDOC/firstProject/User.ashx?action=Get_OrderMoneyOne",
				data: {
					"Quhuo_Lng": userAddObj.Quhuo_Lng,
					"Quhuo_Lat": userAddObj.Quhuo_Lat,
					"Shouhuo_Lng": userAddObj.Shouhuo_Lng,
					"Shouhuo_Lat": userAddObj.Shouhuo_Lat,
					"GoodsMoney": resPrice,
					"Flag": "0",
				},
				dataType: "json",
				success: function(data) {
					if(data.msg == "成功"){
						//console.log(data);
						orderMoney = data.data.OrderMoney;
						moneyDetail = data.data.moneyDetail;
						$(".money_detail").html(moneyDetail);
						$(".form_submit").html("费用￥" + orderMoney + ",去支付");
					} else {
						return false
					}
				},
				error: function() {
					//console.log("订单金额接口数据错误");
					return false
				}
			});
		}
		(Near=="0" ? ajaxOrderMoney() : ajaxNearOrderMoney());
		//获取订单价格---就近买
		function ajaxNearOrderMoney(){
			$.ajax({
				type: "post",
				url: currentUrl+"/interfaceDOC/firstProject/User.ashx?action=Get_OrderMoneyOne",
				data: {
					"Quhuo_Lng": userAddObj.Shouhuo_Lng, 
					"Quhuo_Lat": userAddObj.Shouhuo_Lat,
					"Shouhuo_Lng": userAddObj.Shouhuo_Lng,
					"Shouhuo_Lat": userAddObj.Shouhuo_Lat,
					"GoodsMoney": resPrice,
					"Flag": "0",
					// "UserId":userInfoObj.data.UserId
				},
				dataType: "json",
				success: function(data) {
					if(data.msg == "成功") {				
						orderMoney = data.data.OrderMoney;
						moneyDetail = data.data.moneyDetail;
						$(".money_detail").html(moneyDetail);
						$(".form_submit").html("费用￥" + orderMoney + ",去支付");
					} else {
						return false
					}
				},
				error: function() {
                    $.toptip("无法计算路径价格，请重填收货地址", 'error');
					return false
				}
			});
		}
		// 2:保温箱
		var isKeepWarm = $("#keep_warm").is(':checked');
		var Baowenxiang;

		function baowenxiang() {
			if(isKeepWarm == false) {
				Baowenxiang = 0;
			} else {
				Baowenxiang = 1;
			};
		}
		baowenxiang();
		$("#keep_warm").click(function() {
			isKeepWarm = $(this).is(':checked');
			if(isKeepWarm == false) {
				baowenxiang();		
			} else {
				baowenxiang();
			}
		});
		//闪电买购买物品类型交互
		var goodsName=$(".buy_change .name").html();
	$(".buy_type li").on('click', function() {
		$(".buy_type li span").css('visibility', 'hidden');
		$(this).children("span").css("visibility", "visible");
		var buyType = $(this).children("i").attr("class").split(" ")[1];
		var buyName = $(this).find(".name").html();
		var str="";
		str += "<i class='iconfont " + buyType + "'></i><div class='name'>" + buyName + "</div>";
		buyTypeStr=str;
		$(".buy_change").html("");
		$(".buy_change").html(str);
		goodsName=buyName;
				//物品类型  后期优化 2017.6.30
				if(goodsName=="任意买"){
					 goodsId="19";
				}else if(goodsName=="咖啡"){
					 goodsId="2";
				}else if(goodsName=="水果"){
					 goodsId="20";
				}else if(goodsName=="蛋糕"){
					 goodsId="5";
				}else if(goodsName=="鲜花"){
					 goodsId="1";
				}else if(goodsName=="药品"){
					 goodsId="21";
				}else if(goodsName=="宵夜"){
					 goodsId="24"; //后台数据 美食ID 24
				}else if(goodsName=="快餐"){
					 goodsId="24";
				}else{
					 goodsId="19"
				}
		sessionStorage.setItem("buyTypeStr",buyTypeStr);
		sessionStorage.setItem("goodsId",goodsId);	
	})
 
		var buyTypeStr=sessionStorage.getItem("buyTypeStr");
		var goodsId=sessionStorage.getItem("goodsId");
		if(goodsId){
			goodesId=sessionStorage.getItem("goodsId");
		}else{
			goodsId="19";
		}
		if(buyTypeStr){
			$(".buy_change").empty();
			$(".buy_change").html(buyTypeStr);
		}
		//     submit提交  正则检验
		$(".form_submit").on('click', function() {
			if($("#product_mes").val() == "") {
				$.alert("告诉我商品信息");
				return false;
			} else if(QuHuoAddress == ""&& Near!="1") {
				$.alert("请输入购买地址")
				return false;
			} else if(ShouhuoAddress == "") {
				$.alert("请输入地址信息")
				return false;
			} else if($("#res_price").val() == "") {
				$.alert("请输入商品价格")
				return false;
			} else if($("#user_tel").val() == "") {
				$.alert("请输入联系号码")
				return false;
			} else {
				Desc = $("#product_mes").val();
				var UserId = userInfoObj.data.UserId;

				if(Near=="0"){
					var orderData = {
						"Near": Near,
						"Baowenxiang": Baowenxiang,
						"QuHuoAddress": QuHuoAddress,
						"Quhuo_Lng": userAddObj.Quhuo_Lng,
						"Quhuo_Lat": userAddObj.Quhuo_Lat,
						"Quhuo_Person": userAddObj.Quhuo_Person,
						"Quhuo_Tel": userAddObj.Quhuo_Tel,
						"ShouhuoAddress": ShouhuoAddress,
						"Shouhuo_Lng": userAddObj.Shouhuo_Lng,
						"Shouhuo_Lat": userAddObj.Shouhuo_Lat,
						"Shouhuo_Person": userAddObj.Shouhuo_Person,
						"Shouhuo_Tel": userAddObj.Shouhuo_Tel,
						"GoodsId": goodsId,
						"ZhiPrice": zhiPrice,
						"WuPin_Money": resPrice,
						"Desc": Desc,
						"YiSui": "0",
						"Quhuo_Date": nowTime,
						"YouId": "0",
						"YouMoney": "0",
						"OrderMonery": orderMoney,
						"CityId": "155",
						"UserId": UserId,
						"Types": "0",
						"IsTouBao": "0",
						"TouMoney": "0",
						"PeiMoney": "0",
					}
				}else if(Near=="1"){
					var nearBuyAdd="在"+userAddObj.ShouhuoAddress+"附近";
					var orderData = {
						"Near": Near,
						"Baowenxiang": Baowenxiang,
						"QuHuoAddress": nearBuyAdd,
						"Quhuo_Lng": userAddObj.Shouhuo_Lng,
						"Quhuo_Lat": userAddObj.Shouhuo_Lat,
						"Quhuo_Person": userAddObj.Shouhuo_Person,
						"Quhuo_Tel": userAddObj.Shouhuo_Tel,
						"ShouhuoAddress": userAddObj.ShouhuoAddress,
						"Shouhuo_Lng": userAddObj.Shouhuo_Lng,
						"Shouhuo_Lat": userAddObj.Shouhuo_Lat,
						"Shouhuo_Person": userAddObj.Shouhuo_Person,
						"Shouhuo_Tel": userAddObj.Shouhuo_Tel,
						"GoodsId": goodsId,
						"ZhiPrice": zhiPrice,
						"WuPin_Money": resPrice,
						"Desc": Desc,
						"YiSui": "0",
						"Quhuo_Date": nowTime,
						"YouId": "0",
						"YouMoney": "0",
						"OrderMonery": orderMoney,
						"CityId": "155",
						"UserId": UserId,
						"Types": "0",
						"IsTouBao": "0",
						"TouMoney": "0",
						"PeiMoney": "0",
				}
			}
				orderData = JSON.stringify(orderData);
				sessionStorage.setItem("orderData", orderData);
				window.location.href = "payment_buy.html";
			}
		})